using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(ABPresetting))]
public class ABPresettingEditor : Editor
{
    public override void OnInspectorGUI()
    {
        ABPresetting ab = target as ABPresetting;

        EditorGUI.BeginChangeCheck();
        SerializedProperty tactic_ser = serializedObject.FindProperty("packTactics");
        EditorGUILayout.PropertyField(tactic_ser);

        Match(ab);
        
        SerializedProperty matchingPath_ser = serializedObject.FindProperty("matchingPath");
        EditorGUILayout.PropertyField(matchingPath_ser);
        SerializedProperty m_guid_ser = serializedObject.FindProperty("m_guid");
        EditorGUILayout.PropertyField(m_guid_ser);
        SerializedProperty customABName_ser = serializedObject.FindProperty("customABName");
        EditorGUILayout.PropertyField(customABName_ser);

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
    }

    private void Match(ABPresetting ab)
    {
        string path = AssetDatabase.GetAssetPath(ab.GetInstanceID());
        ab.MatchingPath = path;
        ab.Guid = AssetDatabase.AssetPathToGUID(path);
    }
}
